﻿<?xml version="1.0" encoding="utf-8"?>
<!--
        作者：          liuleyi
        更新时间：      20170227
        用途：          生成存储过程默认模板
-->
<xsl:stylesheet version="2.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xmlns:fn="http://www.w3.org/2005/xpath-functions">
	<xsl:output method="text" indent="no" encoding="utf-8" byte-order-mark="no"/>  
	<xsl:template match="/">
	<xsl:result-document encoding="utf-8" method="text" href="./generate/python/db.py">
	<xsl:variable name="StringTypeDefine" select="document('../model/0101_StringTypeDefine.xml')"/>
	<xsl:variable name="EnumTypeDefine" select="document('../model/0102_EnumTypeDefine.xml')"/>
	<xsl:variable name="BooleanTypeDefine" select="document('../model/0103_BooleanTypeDefine.xml')"/>
	<xsl:variable name="DateTypeDefine" select="document('../model/0104_DateTypeDefine.xml')"/>
	<xsl:variable name="NumberTypeDefine" select="document('../model/0105_NumberTypeDefine.xml')"/>
	<xsl:variable name="IntegerTypeDefine" select="document('../model/0106_IntegerTypeDefine.xml')"/>#-*- encoding:UTF-8 -*-
import cx_Oracle
from . import constant
from . import model
SESSION_MIN = 1
SESSION_MAX = 9
SESSION_INCR = 2
USER_NAME = "lzz"
PASSWORD = "oracle"
DATABASE = "192.168.11.128:1521/TEST1"
pool = cx_Oracle.SessionPool(user=USER_NAME,password=PASSWORD,dsn=DATABASE,min=SESSION_MIN,max=SESSION_MAX,increment=SESSION_INCR)
<xsl:for-each select="FunNoConfig/FunNo">
#<xsl:value-of select="@label"/>
def <xsl:value-of select="@code"/>(Pi_Operid,<xsl:for-each select="Request"><xsl:for-each select="Column">Pi_<xsl:value-of select="@name"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each>
</xsl:for-each>):
    conn  = pool.acquire()
    cursor = conn.cursor()
    errorObj = None
    Po_Cursor = cursor.var(cx_Oracle.CURSOR)
    Pi_OperPara = &quot;&quot;
    Pi_Opertimestamp = &quot;&quot;
    mm = model.DB_EXE_PKG
    mm.ErrorCode = 0
    mm.ErrorMsg = ""
    mm.listdata = []
    try:
        l_Cur,l_Operid,l_Opertimestamp,l_OperPara,<xsl:for-each select="Request">
<xsl:for-each select="Column">l_<xsl:value-of select="@name"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each>
</xsl:for-each> = cursor.callproc(&quot;<xsl:value-of select="@code"/>&quot;, (Po_Cursor,Pi_Operid,Pi_Opertimestamp,Pi_OperPara,<xsl:for-each select="Request">
<xsl:for-each select="Column">Pi_<xsl:value-of select="@name"/><xsl:if test="position()!=last()">,</xsl:if></xsl:for-each>
</xsl:for-each>))
 <xsl:variable name="Resonse" select="count(Response)"/><xsl:choose><xsl:when test="$Resonse!=0">

        for row in l_Cur:
            data = {}
            <xsl:for-each select="Response"><xsl:for-each select="Column">
            data[constant.GV_<xsl:value-of select="@name"/>] = row[<xsl:value-of select="position()-1"/>]
            </xsl:for-each>
            </xsl:for-each>
            mm.listdata.append(data)
 </xsl:when><xsl:otherwise></xsl:otherwise></xsl:choose>
    
    except cx_Oracle.Error as e:
        errorObj, = e.args
        mm.ErrorCode = errorObj.code
        mm.ErrorMsg = errorObj.message

    return mm
</xsl:for-each>
</xsl:result-document></xsl:template>  
</xsl:stylesheet>